# lf provides a function lfcd to cd into lf current directory on quit.

# This implies you must execute either lf or lfcd and cannot change your mind about whether to cd to the current directory on quit after running one or the other.

# Following allows to quit lf normally using q hotkey or cd to current directory on quit using Q hotkey.

# Create script lf.bash in your ~/.config/lf directory with following contents:

# Source this file in your .bashrc:

# source ~/.config/lf/lf.bash

lf() {
    export LF_CD_FILE=/var/tmp/.lfcd-$$
    command lf $@
    if [ -s "$LF_CD_FILE" ]; then
        local DIR="$(realpath "$(cat "$LF_CD_FILE")")"
        if [ "$DIR" != "$PWD" ]; then
            echo "cd to $DIR"
            cd "$DIR"
        fi
        rm "$LF_CD_FILE"
    fi
    unset LF_CD_FILE
}
